/*
 * *
 *  * Created with IntelliJ RustRover.
 *  * Description:
 *  * Copyright Author: ZhenYi
 *  * DateTime: 2024/2/14 下午5:10
 *
 */


use serde::{Deserialize, Serialize};

#[derive(Deserialize,Serialize,Clone)]
pub struct Redis{
    ip:String,
    password:String
}


impl Default for Redis {
    fn default() -> Self {
        Self{
            ip:String::new(),
            password:String::new()
        }
    }
}

impl Redis {
    pub fn format_nohead(&self) ->String{
        self.ip.clone()
    }
    pub fn format(&self) ->String{
        if self.password.is_empty() {
            format!("redis://{}",self.ip)
        }else {
            format!("redis://{}@{}",self.password,self.ip)
        }
    }
}